package com.bst.base.service.impl;

import java.util.Date;
import java.util.List;

import com.bst.common.utils.self.LoginAPIUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bst.base.mapper.BaseReportDateMapper;
import com.bst.base.domain.BaseReportDate;
import com.bst.base.service.IBaseReportDateService;
import com.bst.common.core.text.Convert;

/**
 * 通用上报时间Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-05-07
 */
@Service
public class BaseReportDateServiceImpl implements IBaseReportDateService 
{
    @Autowired
    private BaseReportDateMapper baseReportDateMapper;

    /**
     * 查询通用上报时间
     * 
     * @param idReport 通用上报时间主键
     * @return 通用上报时间
     */
    @Override
    public BaseReportDate selectBaseReportDateByIdReport(Long idReport)
    {
        return baseReportDateMapper.selectBaseReportDateByIdReport(idReport);
    }

    /**
     * 查询通用上报时间列表
     * 
     * @param baseReportDate 通用上报时间
     * @return 通用上报时间
     */
    @Override
    public List<BaseReportDate> selectBaseReportDateList(BaseReportDate baseReportDate)
    {
        return baseReportDateMapper.selectBaseReportDateList(baseReportDate);
    }

    /**
     * 新增通用上报时间
     * 
     * @param baseReportDate 通用上报时间
     * @return 结果
     */
    @Override
    public int insertBaseReportDate(BaseReportDate baseReportDate)
    {
        baseReportDate.setDtSysCre(new Date());
        baseReportDate.setNaEmpCre(LoginAPIUtils.getLoginUsename());
        return baseReportDateMapper.insertBaseReportDate(baseReportDate);
    }

    /**
     * 修改通用上报时间
     * 
     * @param baseReportDate 通用上报时间
     * @return 结果
     */
    @Override
    public int updateBaseReportDate(BaseReportDate baseReportDate)
    {
        return baseReportDateMapper.updateBaseReportDate(baseReportDate);
    }

    /**
     * 批量删除通用上报时间
     * 
     * @param idReports 需要删除的通用上报时间主键
     * @return 结果
     */
    @Override
    public int deleteBaseReportDateByIdReports(String idReports)
    {
        return baseReportDateMapper.deleteBaseReportDateByIdReports(Convert.toStrArray(idReports));
    }

    /**
     * 删除通用上报时间信息
     * 
     * @param idReport 通用上报时间主键
     * @return 结果
     */
    @Override
    public int deleteBaseReportDateByIdReport(Long idReport)
    {
        return baseReportDateMapper.deleteBaseReportDateByIdReport(idReport);
    }

    @Override
    public BaseReportDate getNewBaseReportDate(String type,String dayEnd) {
        BaseReportDate date = new BaseReportDate();
        date.setSdReportType(type);
        List<BaseReportDate> dates = this.selectBaseReportDateList(date);
        if(dates.size()>0) {
            date = dates.get(0);
            date.setdBegin(dates.get(0).getdEnd());
            date.setdEnd(dayEnd);
            if(dayEnd.compareTo(date.getdBegin())<=0) {
                return null;
            }
            return date;
        } else {
            return null;
        }
    }
}
